package treepro;

import java.util.Date;
import org.jdesktop.application.Task;

/**
 *
 * @author Ivan
 */
public class RefreshTask extends Task {

    RefreshTask(org.jdesktop.application.Application app) {
        super(app);
    }

    public boolean alive = true;
    public String message = "Идет расчет...";
    @SuppressWarnings("unchecked")
    @Override
    protected Void doInBackground() {
        try {
            //setProgress(0, 0, 4);
            setMessage(message);
            //setProgress(1, 0, 4);
            //entityManager.getTransaction().rollback();
            //Thread.sleep(1000L); // remove for real app
            //setProgress(2, 0, 4);
            
            //setMessage("Starting a new transaction...");
            //entityManager.getTransaction().begin();
            //Thread.sleep(500L); // remove for real app
            //setProgress(3, 0, 4);
            
            //setMessage("Fetching new data...");
            while (alive) {
                TreeProApp.main.labelTime.setText(calcsdk.nw.Util.getDiffTime(TreeProApp.dateStart.getTime(), (new Date()).getTime()));
                Thread.sleep(500); // remove for real app
            }
            //setProgress(4, 0, 4);
            
            //Thread.sleep(150L); // remove for real app
            //list.clear();
            //list.addAll(data);
        } catch (InterruptedException ignore) {
        }
        return null;
    }

    @Override
    protected void finished() {
        setMessage("Готово");
        //setSaveNeeded(false);
    }    
}
